import React from 'react';
import VoteHead from './VoteHead';
import VoteMain from './VoteMain';
import VoteFooter from './VoteFooter';
import subscribe from '../assets/subscribe';
window.$sub = new subscribe();

class Vote extends React.Component {
	state = {
		supNum: 0,
		oppNum: 0
	};
	changeNum = type => {
		if (type === 0) {
			this.setState({
				supNum: ++this.state.supNum
			});
			return;
		}
		this.setState({
			oppNum: ++this.state.oppNum
		});
	};
	render() {
		let { title } = this.props;
		let { supNum, oppNum } = this.state;

		return <section>
			<VoteHead title={title} supNum={supNum} oppNum={oppNum} />
			<VoteMain supNum={supNum} oppNum={oppNum} />
			<VoteFooter />
		</section>;
	}
	componentDidMount() {
		window.$sub.$on(this.changeNum);
	}
}
export default Vote;